﻿using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
using MauiControl.Services;
using System.Diagnostics;
using System.Threading.Tasks;
using MauiControl.ViewModels;
using MauiControl.Views;
using CommunityToolkit.Maui;



#if ANDROID
using MauiControl.Platforms.Android.Services;
#elif IOS
using MauiControl.Platforms.iOS.Services;
#elif MACCATALYST
using MauiControl.Platforms.MacCatalyst.Services;
#elif WINDOWS
using MauiControl.Platforms.Windows.Services;
#endif

namespace MauiControl
{
    public static class MauiProgram
    {

        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .UseMauiCommunityToolkit()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                    fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                });


            // 配置依赖注入
#if ANDROID
            builder.Services.AddSingleton<IBluetoothService, BluetoothServiceAndroid>();
#elif IOS
            builder.Services.AddSingleton<IBluetoothService, BluetoothServiceiOS>();
#elif MACCATALYST
            builder.Services.AddSingleton<IBluetoothService, BluetoothServiceMacCatalyst>();
#elif WINDOWS
            builder.Services.AddSingleton<IBluetoothService, BluetoothServiceWindows>();
#endif

            builder.Services.AddSingleton<BluetoothService>();
            // 注册服务
            builder.Services.AddSingleton<INavigationService, NavigationService>();

            // 注册 ViewModel
            builder.Services.AddTransient<MainPageViewModel>();
            builder.Services.AddTransient<DeviceSearchPageViewModel>();

            // 注册页面
            builder.Services.AddTransient<MainPage>();
            builder.Services.AddTransient<DeviceSearchPage>();


#if DEBUG
            builder.Logging.AddDebug();
#endif

            return builder.Build();
        }
    }
}
